React = require('react')
Card = require('antd-mobile/lib/card')
ListView = require('antd-mobile/lib/list-view')
Flex = require('antd-mobile/lib/flex')
Icon = require('antd-mobile/lib/icon')
Toast = require('antd-mobile/lib/toast')
List = require('antd-mobile/lib/list')
RefreshControl = require('antd-mobile/lib/refresh-control')
{View,Image,Text,ScrollView,TouchableHighlight,StyleSheet,Navigator,ListView,TouchableOpacity} = require('react-native')
Dimensions = require('Dimensions')
{ width, height } = require('../utilities/getScreen.js')
{View} = require('react-native')
{fetchGetList,fetchRefreshList} = require('../actions/page_yhsj.js')
{connect} = require('react-redux')
_ = require('underscore')




backImg = require('../img/back.png')
searchIcon = require('../img/search_white.png')
renderAfterTransfer = require('../highOrderComponent/renderAfterTransfer.js')
class Page_yhjh extends React.Component
  componentDidMount:->
    @props.fetchGet()
  renderHeader:->
      <View style={{flexDirection:'row',flex:0,height:60,alignItems:'center', justifyContent:'center',backgroundColor:'#0066FF'}}>
        <View style={{flex:1,padding:10}}>
          <TouchableOpacity onPress={=>@props.navigator.pop()}>
            <Image source={backImg}  style={{height:30,width:30,resizeMode:'contain'}}/>
          </TouchableOpacity>
        </View>
        <View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
          <Text style={{fontSize:20,color:'#ffffff'}}>引航数据</Text>
        </View>
        <View style={{flex:1,alignItems:'flex-end',padding:10}}>
          <TouchableOpacity onPress={@_showActionSheet}>
          </TouchableOpacity>
        </View>
      </View>

  renderBody:->
    <ScrollView style={{flexDirection:'column',backgroundColor:'#ffffff',paddingTop:10}}>
      <List>
        {
          do =>
            coll  = _.pairs @props.list
            items = for item in coll when item[0] isnt 'year'
              <List.Item key={item[0]} extra="#{item[1]}">{"#{parseInt(item[0])}月"}</List.Item>
            items.push <List.Item key='year' extra={<Text style={{fontWeight:"bold",fontSize:20}}>{@props.list['year']}</Text>}>全年</List.Item>
            items
        }
      </List>

    </ScrollView>
    # <ScrollView style={{flexDirection:'column',backgroundColor:'#ffffff',paddingTop:10}}>
    #   {
    #     do =>
    #       coll  = _.pairs @props.list
    #       rel = for item in coll when item[0] isnt 'year'
    #               <View key={item[0]} style={styles.rowContainer}>
    #                 <View style={styles.leftContainer}>
    #                   <Text style={styles.leftText}>{"#{parseInt(item[0])}月"}</Text>
    #                 </View>
    #                 <View style={styles.rightContainer}>
    #                   <Text style={styles.rightText}>{item[1]}</Text>
    #                 </View>
    #               </View>
    #       rel.push  <View key="year" style={styles.rowContainer}>
    #                   <View style={styles.leftContainer}>
    #                     <Text style={styles.leftText}>年度</Text>
    #                   </View>
    #                   <View style={styles.rightContainer}>
    #                     <Text style={styles.rightText}>{@props.list['year']}</Text>
    #                   </View>
    #                 </View>
    #       rel
    #
    #   }
    # </ScrollView>

  render:->
    debugger
    <View style={width:width,height:height,flexDirection:'column',backgroundColor:'#ffffff',paddingBottom:20}>
      {@renderHeader()}
      {
        if  @props.completed
          @renderBody()
      }
  </View>


styles = StyleSheet.create
  rowContainer:
    flexDirection:'row'
    paddingBottom:10
  leftContainer:
    backgroundColor:'#90d7ec'
    width:150
    flexDirection:'column'
    justifyContent:'center'
    alignItems:'center'
  rightContainer:
    backgroundColor:'#ffffff'
    flexDirection:'column'
    justifyContent:'center'
    alignItems:'center'
    flex:1
  leftText:
    color:'#ffffff'
    fontSize:30
  rightText:
    color:'#000000'
    fontSize:20

mapStateToProps = (state)->
  list:state.page_yhsj.list
  isLoading:state.page_yhsj.isLoading
  completed:state.page_yhsj.completed
  refreshing:state.page_yhsj.refreshing
mapDispatchToProps = (dispatch,wonProps)->
  fetchGet:()->
    dispatch fetchGetList()
  fetchRefresh:->
    dispatch fetchRefreshList()
Page_yhjh = renderAfterTransfer(Page_yhjh)
module.exports = connect(mapStateToProps,mapDispatchToProps)(Page_yhjh)
